package com.nowcoder.project.service;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.nowcoder.project.dao.BookDAO;
import com.nowcoder.project.model.Book;
import com.nowcoder.project.model.enums.BookStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by nowcoder on 2018/08/04 下午3:41
 */
@Service
public class BookService {

    @Autowired
    private BookDAO bookDAO;

    public List<Book> getAllBooks() {
        return bookDAO.selectAll();
    }

    public Page<Book> getBooksByPage(int pageNum, int pageSize) {
        Page<Book> page = PageHelper.startPage(pageNum, pageSize);
        bookDAO.selectAll();
        return page;
    }

    public int addBooks(Book book) {
        return bookDAO.addBook(book);
    }

    public void deleteBooks(int id) {
        bookDAO.updateBookStatus(id, BookStatusEnum.DELETE.getValue());
    }

    public void recoverBooks(int id) {
        bookDAO.updateBookStatus(id, BookStatusEnum.NORMAL.getValue());
    }

    public int updateBook(Book book) {
        return bookDAO.updateBook(book);
    }
}
